package com.xzl.xep.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xzl.xep.pojo.Company;
import com.xzl.xep.service.CashService;


@Controller
@RequestMapping(value ="/cash" )
public class CashController extends BaseController {

	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(ProductController.class);
	
	@Autowired
	private CashService service;
	
	
	@RequestMapping(value ="", method=RequestMethod.GET )
	public String cash(Model model) {
		model.addAttribute("plusList", service.getPlusList(companyId));
		model.addAttribute("minusList", service.getMinusList(companyId));
		model.addAttribute("company", service.loadObject(Company.class, companyId));
		return "finance/cash";
	}
	
	@RequestMapping(value ="/plus", method=RequestMethod.GET )
	public String plusCash() {
		
		return "finance/cashOver";
	} 
	
	@RequestMapping(value ="/minus", method=RequestMethod.GET )
	public String minusCash() {
		
		return "finance/cashOver";
	}
	
	
	
	
	
	
	@RequestMapping(value ="/plus", method=RequestMethod.POST )
	@ResponseBody
	public Map<String,Object> plusCash(Double money,String remark) {
		if(companyId ==null || companyId ==0)
			return null;
		
		if(money!=null && money > 0){
			Map<String,Object> map = new HashMap<String ,Object>();
			map.put("cash", service.plusCash(operator,money,remark));
			map.put("company", service.loadObject(Company.class, companyId));
			return map;
		}
		return null;
	} 
	
	@RequestMapping(value ="/minus", method=RequestMethod.POST )
	@ResponseBody
	public Map<String,Object> minusCash(Double money,String remark) {
		
		if(companyId ==null || companyId ==0)
			return null;
		
		if(money!=null && money > 0){
			Map<String,Object> map = new HashMap<String ,Object>();
			map.put("cash", service.minusCash(operator,money,remark));
			map.put("company", service.loadObject(Company.class, companyId));
			return map;
		}
		return null;
	}
	
	
}
